//
//  ClinicInventoryController.m
//  XinTaiPub
//
//  Created by rzhyios on 2018/5/31.
//  Copyright © 2018年 rzhy. All rights reserved.
//

#import "ClinicInventoryController.h"
#import "Config.h"
#import <UIScrollView+EmptyDataSet.h>
#import "Patient.h"
#import "InventoryTableViewCell.h"
#import "ClinicInvenDetailVC.h"
static NSString * const CellIdentifier = @"Cell";

@interface ClinicInventoryController ()<UITableViewDataSource, UITableViewDelegate>
{
    Patient *_patient;
    NSArray *_dataArray;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ClinicInventoryController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"每日清单";
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    UINib *nib = [UINib nibWithNibName:[InventoryTableViewCell registerName] bundle:nil];
    [_tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
    _patient = [Patient sharedPatient];
    [self getZymrqdlb];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 住院每日清单列表
- (void)getZymrqdlb {
    NSDictionary *cookie = @{CookieVaule : [UserDefaultsTool stringForKey:XHToken]};
    NSDictionary *param = @{@"id" : @(_patient.id)};
    [HTTPSTool POSTRequestWithPath:XHUserMzmrqdlb cookie:cookie params:param success:^(NSDictionary * _Nonnull JSON) {
        XHLog(@"住院每日清单列表 -> JSON: %@", JSON);
        _dataArray = JSON[@"data"][@"list"];
        [_tableView reloadData];
    }];
}

#pragma mark - tableView delegate/dataSource Method
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 55.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    InventoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    NSDictionary *dict = _dataArray[indexPath.row];
    [cell setCellShowDatWithDataDictionary:dict];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    NSDictionary *dict = _dataArray[indexPath.row];
    NSString *fyrq = dict[@"fyrq"];
    NSString *amt = dict[@"sum"];
//    NSString *urlString = [NSString stringWithFormat:@"%@?id=%ld&date=%@&amt=%@", XHUserZymrqdmx, (long)_patient.id, fyrq, zjje];
//    NSURL *url = [URLTool webURLStringWithPathString:urlString token:[UserDefaultsTool stringForKey:XHToken]];
    ClinicInvenDetailVC *vc = [[ClinicInvenDetailVC alloc] init];
    vc.amt = amt;
    vc.fyrq = fyrq;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - DZNEmptyDataSetSource Method
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    UIImage *image = [UIImage imageNamed:@"LoadFailure.png"];
    return image;
}

- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *string = XHEmptyDes;
    NSAttributedString *abs = [[NSAttributedString alloc] initWithString:string attributes:nil];
    return abs;
}

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
    return -64.0f;
}

#pragma mark - DZNEmptyDataSetDelegate Method
- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView {
    return YES;
}

- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView {
    return YES;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return YES;
}

- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
    [self getZymrqdlb];
}



@end
